<template>
  <div class="ratingselect">
    <div class="rating-type border-1px">
      <span class="block positive" v-for="(type,index) in ratingSelectType" :class="{'active':selectType===type.type}" @click="select(type.type)">
        {{ type.tab }}<span class="count">{{selectCount[index]}}</span>
      </span>
    </div>
    <div class="switch" @click="toggleOnly" :class="{'on':onlyContent}">
      <i class="icon-check_circle"></i>
      <span class="text">只看有内容的评价</span>
    </div>
  </div>
</template>

<script type="text/ecmascript-6">
  /* eslint-disable no-unused-vars */
  const POSITIVE = 0
  /* eslint-disable no-unused-vars */
  const NEGATIVE = 1
  const ALL = -1

  export default{
    props: {
      ratings: {
        type: Array,
        default () {
          return []
        }
      },
      selectType: {
        type: Number,
        default: ALL
      },
      onlyContent: {
        type: Boolean,
        default: false
      },
      ratingSelectType: {
        type: Array
      }
    },
    computed: {
      selectCount () {
        let counts = []
        this.ratingSelectType.forEach((type) => {
          let count = 0
          if (type.type === ALL) {
            counts.push(this.ratings.length)
          } else {
            this.ratings.forEach((rating) => {
              if (rating.rateType === type.type) {
                count += 1
              }
            })
            counts.push(count)
          }
        })
        return counts
      }
    },
    methods: {
      toggleOnly () {
        this.$emit('toggleOnly')
      },
      select (type) {
        this.$emit('selectRatingType', type)
      }
    }
  }
</script>

<style rel="stylesheet/stylus" lang="stylus">
  @import '../../common/stylus/mixin.styl'

  .ratingselect
    .rating-type
      padding: 18px 0
      margin: 0 18px
      border-1px(rgba(7, 17, 27, .1))
      font-size: 0
      .block
        display: inline-block
        padding: 8px 12px
        margin-right: 8px
        border-radius: 1px
        line-height: 16px
        color: rgb(77, 85, 93)
        font-size: 12px
        &.active
          color: #fff
        &.positive
          background: rgba(0, 160, 220, .2)
          &.active
            background: rgb(0, 160, 220)
        &.negative
          background: rgba(77, 85, 93, .2)
          &.active
            background: rgb(77, 85, 93)
        .count
          font-size: 8px
          margin-left: 2px
    .switch
      padding: 12px 18px
      line-height: 24px
      border-bottom: 1px solid rgba(7, 17, 27, .1)
      color: rgb(147, 153, 159)
      font-size: 0
      &.on
        .icon-check_circle
          color: #00c850
      .icon-check_circle
        display: inline-block
        vertical-align: top
        margin-right: 4px
        font-size: 24px
      .text
        display: inline-block
        vertical-align: top
        font-size: 12px

</style>
